﻿//using UnityEngine;
//using System.Collections;
//using System.Collections.Generic;

//namespace Battle.View
//{
//    public enum CameraState
//    {
//        None,
//        EnterBattleScene,   //进场
//        BattleReady,        //默认

//        BattleAttackMelee,  //近战攻击  Attacker 中间位子
//        BattleAttackMeleeL,  //近战攻击  Attacker 左边位子
//        BattleAttackMeleeR,  //近战攻击  Attacker 右边位子

//        BattleAttackRemote, //远程攻击  Attacker

//        BattleDefend,       //防御 Defender的攻击

//        SwitchCamp,      //换阵视角
//        BattleOver,      //战斗结束
//        BattleUltimate,  //大招
//    }

//    public delegate void Invoke();

//    public class CameraController
//    {
//        #region instance
//        private static CameraController _instance;
//        public static CameraController Instance
//        {
//            get
//            {
//                if (_instance == null)
//                    _instance = new CameraController();
//                return _instance;
//            }
//        }
//        private CameraController()
//        {

//            mainCamera = UnityEngine.Camera.main;

//            animationKit = mainCamera.GetComponent<CameraAnimationKit>();
//            if (animationKit != null)
//            {
//                animationKit.Init();
//            }
//        }
//        #endregion

//        UnityEngine.Camera mainCamera;
//        CameraAnimationKit animationKit;
//        CameraState curState = CameraState.None;


//        bool isCameraTraveling = false;
//        float cameraTravelingTime = 0f;
//        public void Tick()
//        {
//            if (isCameraTraveling)
//            {
//                cameraTravelingTime -= Time.deltaTime;
//                if (cameraTravelingTime <= 0)
//                {
//                    isCameraTraveling = false;
//                }
//            }
//        }

//        public bool IsCameraTraveling()
//        {
//            return isCameraTraveling;
//        }

//        public float GetUltimateAniLength()
//        {
//            return animationKit.GetAniLength(CameraAnimationType.ULTIMATE_SKILL_P1);
//        }

//        void Play(CameraAnimationType at, bool isRevert = false, bool isCrossFade = true, float speed = 1)
//        {
//            animationKit.Play(at, isRevert, isCrossFade, speed);
//            cameraTravelingTime = animationKit.GetAniLength(at);
//            isCameraTraveling = true;
//        }
//        /// <summary>
//        /// 摄像机入场
//        /// </summary>
//        public void Entrance()
//        {
//            curState = CameraState.EnterBattleScene;
//            Play(CameraAnimationType.PVP_ENTER_SCENE);
//        }

//        public void Ready()
//        {
//            switch (curState)
//            {
//                case CameraState.SwitchCamp:
//                    Play(CameraAnimationType.SWITCH_CAMP, true);
//                    break;
//                case CameraState.BattleAttackMelee:
//                    Play(CameraAnimationType.PVP_RUSH_NEAR, true);
//                    break;
//                case CameraState.BattleAttackRemote:
//                    Play(CameraAnimationType.PVP_RUSH_FAR, true);
//                    break;
//                case CameraState.BattleDefend:
//                    Play(CameraAnimationType.PVP_OUR_TEAM_BEHIT, true);
//                    break;
//                default:
//                    // CameraState.BattleOver
//                    // CameraState.BattleReady 
//                    // CameraState.BattleUltimate
//                    // CameraState.EnterBattleScene
//                    // CameraState.None
//                    break;
//            }
//            curState = CameraState.BattleReady;
//        }

//        public void SwitchCamp()
//        {
//            curState = CameraState.SwitchCamp;
//            Play(CameraAnimationType.SWITCH_CAMP);
//        }


//        public void Attack(bool isMelee, BattleCamp camp, int fpid)
//        {
//            if (camp == BattleCamp.Attacker)
//            {
//                if (curState == CameraState.BattleReady)
//                {
//                    if (isMelee)
//                    {
//                        /*
//                        if( fpid == 3 || fpid == 8 || fpid == 13 )
//                        {
//                            curState = CameraState.BattleAttackMelee;
//                            animationKit.Play( CameraAnimationType.PVP_RUSH_NEAR );
//                            float delayTime = animationKit.GetAniLength( CameraAnimationType.PVP_RUSH_NEAR );
//                            animationKit.PlayDelay( CameraAnimationType.PVP_NEAR_BATTLING, delayTime );
//                        }
//                        else if(fpid == 1 || fpid == 2 || fpid == 6 || fpid == 7 || fpid == 11 || fpid == 12)
//                        {
//                            curState = CameraState.BattleAttackMeleeL;
//                            animationKit.Play( CameraAnimationType.PVP_RUSH_NEAR_L );
//                            float delayTime = animationKit.GetAniLength( CameraAnimationType.PVP_RUSH_NEAR_L );
//                            animationKit.PlayDelay( CameraAnimationType.PVP_NEAR_BATTLING_L, delayTime );
//                        }
//                        else if( fpid == 4 || fpid == 5 || fpid == 9 || fpid == 10 || fpid == 14 || fpid == 15 )
//                        {
//                            curState = CameraState.BattleAttackMeleeR;
//                            animationKit.Play( CameraAnimationType.PVP_RUSH_NEAR_R );
//                            float delayTime = animationKit.GetAniLength( CameraAnimationType.PVP_RUSH_NEAR_R );
//                            animationKit.PlayDelay( CameraAnimationType.PVP_NEAR_BATTLING_R, delayTime );
//                        }
//                         * */

//                        //暂时决定全部用统一摄像机
//                        curState = CameraState.BattleAttackMelee;
//                        animationKit.Play(CameraAnimationType.PVP_RUSH_NEAR);
//                        float delayTime = animationKit.GetAniLength(CameraAnimationType.PVP_RUSH_NEAR);
//                        animationKit.PlayDelay(CameraAnimationType.PVP_NEAR_BATTLING, delayTime);

//                        //test
//                    }
//                    else
//                    {
//                        curState = CameraState.BattleAttackRemote;
//                        animationKit.Play(CameraAnimationType.PVP_RUSH_FAR);
//                        float delayTime = animationKit.GetAniLength(CameraAnimationType.PVP_RUSH_FAR);
//                        animationKit.PlayDelay(CameraAnimationType.PVP_FAR_BATTLING, delayTime);
//                    }
//                }
//                else if (curState == CameraState.BattleAttackMelee
//                    || curState == CameraState.BattleAttackMeleeL
//                    || curState == CameraState.BattleAttackMeleeR)
//                {
//                    if (isMelee)
//                    {
//                        /*
//                        if( fpid == 3 || fpid == 8 || fpid == 13 )
//                        {
//                            if( curState!= CameraState.BattleAttackMelee )
//                            {
//                                curState = CameraState.BattleAttackMelee;
//                                animationKit.Play( CameraAnimationType.PVP_NEAR_BATTLING );
//                            }
//                        }
//                        else if( fpid == 1 || fpid == 2 || fpid == 6 || fpid == 7 || fpid == 11 || fpid == 12 )
//                        {
//                            if( curState!= CameraState.BattleAttackMeleeL )
//                            {
//                                curState = CameraState.BattleAttackMeleeL;
//                                animationKit.Play( CameraAnimationType.PVP_NEAR_BATTLING_L );
//                            }
//                        }
//                        else if( fpid == 4 || fpid == 5 || fpid == 9 || fpid == 10 || fpid == 14 || fpid == 15 )
//                        {
//                            if( curState != CameraState.BattleAttackMeleeR )
//                            {
//                                curState = CameraState.BattleAttackMeleeR;
//                                animationKit.Play( CameraAnimationType.PVP_NEAR_BATTLING_R );
//                            }
//                        }
//                         * */


//                    }
//                    else
//                    {
//                        curState = CameraState.BattleAttackRemote;
//                        animationKit.Play(CameraAnimationType.PVP_FAR_BATTLING); //直接到远程摇镜头
//                        //animationKit.Play( CameraAnimationType.PVP_RUSH_FAR );
//                        //float delayTime = animationKit.GetAniLength( CameraAnimationType.PVP_RUSH_FAR );
//                        //animationKit.PlayDelay( CameraAnimationType.PVP_FAR_BATTLING, delayTime );
//                    }
//                }
//                else if (curState == CameraState.BattleAttackRemote)
//                {
//                    if (isMelee)
//                    {
//                        if (!BattleViewCtrl.GetInstance().IsHaveRemoteBehaviour())
//                        {
//                            /*
//                            if (fpid == 3 || fpid == 8 || fpid == 13)
//                            {
//                                if (curState != CameraState.BattleAttackMelee)
//                                {
//                                    curState = CameraState.BattleAttackMelee;
//                                    animationKit.Play(CameraAnimationType.PVP_NEAR_BATTLING);
//                                }
//                            }
//                            else if (fpid == 1 || fpid == 2 || fpid == 6 || fpid == 7 || fpid == 11 || fpid == 12)
//                            {
//                                if (curState != CameraState.BattleAttackMeleeL)
//                                {
//                                    curState = CameraState.BattleAttackMeleeL;
//                                    animationKit.Play(CameraAnimationType.PVP_NEAR_BATTLING_L);
//                                }
//                            }
//                            else if (fpid == 4 || fpid == 5 || fpid == 9 || fpid == 10 || fpid == 14 || fpid == 15)
//                            {
//                                if (curState != CameraState.BattleAttackMeleeR)
//                                {
//                                    curState = CameraState.BattleAttackMeleeR;
//                                    animationKit.Play(CameraAnimationType.PVP_NEAR_BATTLING_R);
//                                }
//                            }
//                             * */
//                            curState = CameraState.BattleAttackMelee;
//                            animationKit.Play(CameraAnimationType.PVP_NEAR_BATTLING); //直接到远程摇镜头
//                        }
//                    }
//                    else
//                    {
//                        //远程摇镜中
//                    }
//                }
//                else
//                {

//                }
//            }
//            else
//            {
//                if (curState != CameraState.BattleDefend)
//                {
//                    animationKit.Play(CameraAnimationType.PVP_OUR_TEAM_BEHIT);
//                    float delayTime = animationKit.GetAniLength(CameraAnimationType.PVP_OUR_TEAM_BEHIT);
//                    animationKit.PlayDelay(CameraAnimationType.PVP_OUR_TEAM_BEHITING, delayTime);
//                }

//                curState = CameraState.BattleDefend;
//            }
//        }

//        public void ReadyForUltimateEnd()
//        {
//            Play(CameraAnimationType.ULTIMATE_SKILL_END, true);
//        }
//        public void UltimateEnd()
//        {
//            Play(CameraAnimationType.ULTIMATE_SKILL_END);
//        }
//        public void Ultimate(BattleCamp camp, int FPId)
//        {
//            if (camp == BattleCamp.Attacker)
//            {
//                var delay = 0f;
//                if (FPId == 3)
//                {
//                    animationKit.Play(CameraAnimationType.ULTIMATE_SKILL_P1);
//                    delay = animationKit.GetAniLength(CameraAnimationType.ULTIMATE_SKILL_P1);
//                }
//                else if (FPId == 7)
//                {
//                    animationKit.Play(CameraAnimationType.ULTIMATE_SKILL_P2);
//                    delay = animationKit.GetAniLength(CameraAnimationType.ULTIMATE_SKILL_P2);
//                }
//                else if (FPId == 9)
//                {
//                    animationKit.Play(CameraAnimationType.ULTIMATE_SKILL_P3);
//                    delay = animationKit.GetAniLength(CameraAnimationType.ULTIMATE_SKILL_P3);
//                }
//                else if (FPId == 13)
//                {
//                    animationKit.Play(CameraAnimationType.ULTIMATE_SKILL_P4);
//                    delay = animationKit.GetAniLength(CameraAnimationType.ULTIMATE_SKILL_P4);
//                }

//                //    animationKit.PlayDelay(CameraAnimationType.ULTIMATE_SKILL_END, delay, true);
//                curState = CameraState.BattleUltimate;

//                isCameraTraveling = true;
//                cameraTravelingTime = delay + animationKit.GetAniLength(CameraAnimationType.ULTIMATE_SKILL_END);
//            }
//        }

//        public void Win()
//        {
//            Play(CameraAnimationType.WIN);
//        }
//        public void Lose()
//        {
//            Play(CameraAnimationType.DEFEAD);
//        }

//        public void Shake(int i = 0)
//        {
//            animationKit.Shake(i);
//        }

//        public void FocusCharactor(BattleCharacter bc, float delay = 0f)
//        {
//            GameObject obj = bc.model;
//            animationKit.SetFocusGameObject(obj, delay);
//        }

//        public void UnFocusCharactor(BattleCharacter bc)
//        {
//            GameObject obj = bc.model;
//            animationKit.SetUnFocusGameObject(obj);
//        }
//    }
//    /*
//    public class CameraController :Fsm.FsmControllerBase<CameraState>
//    {
//        #region instance
//        static private CameraController inst;
//        static public CameraController Instance
//        {
//            get
//            {
//                if( inst==null )
//                {
//                    inst = new CameraController();
//                    inst.InitState();
//                }

//                return inst;
//            }
//        }
//        #endregion

//        #region state type flag
//        private CameraState previewStateType;
//        public CameraState PreviewStateType
//        {
//            get
//            {
//                return previewStateType;
//            }
//        }
//        private CameraState currentStateType;
//        public CameraState CurrentStateType
//        {
//            get
//            {
//                return currentStateType;
//            }
//        }
//        #endregion

//        public Camera mainCamera;

//        public CameraAnimationKit animationKit;

//        public CameraAnimationType curAnimationType = CameraAnimationType.NONE;

//        #region fsm
//        public override void InitState()
//        {
//            base.InitState();
           
//            allStates[CameraState.Null] = new NullState( CameraState.Null, this );
//            allStates[CameraState.EnterBattleScene] = new EnterBattleSceneState( CameraState.EnterBattleScene, this );
//            allStates[CameraState.BattleAttack] =  new BattleAttackState( CameraState.BattleAttack, this );
//            allStates[CameraState.BattleCenterWait] = new BattleCenterWaitState( CameraState.BattleCenterWait, this );
//            allStates[CameraState.BattleOver] = new BattleOverState( CameraState.BattleOver, this );
//            allStates[CameraState.BattleUltimate] = new BattleUltimateState(CameraState.BattleUltimate,this);
//            allStates[CameraState.BattleReady] = new BattleReadyState(CameraState.BattleReady,this);
//            allStates[CameraState.SwitchCamp] =new SwitchCampState(CameraState.SwitchCamp,this);

//            SwitchState( CameraState.Null );

//            mainCamera = UnityEngine.Camera.main;

//            animationKit = mainCamera.GetComponent<CameraAnimationKit>();
//            if( animationKit!=null )
//            {
//                animationKit.Init();
//            }
//        }


//        public override void SwitchState( CameraState stateType )
//        {
//            if( currentState != null )
//            {
//                previewStateType = currentState.GetStateType();
//                currentState.Leave();
//            }
//            currentStateType = stateType;
//            currentState = allStates[stateType];
//            currentState.Enter();

//            Debug.Log( "[DEBUG] camera current state:<color=red>"+CurrentStateType.ToString() +"</color>");
//        }
//        #endregion


//    }
//    */
//}